﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【在用绳检测位置】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto在用绳检测位置
    /// </summary>
    public abstract class AutoCheckWireropeDetailPositionMapping : BaseMapping<CheckWireropeDetailPosition, CheckWireropeDetailPositionModel, CheckWireropeDetailPositionFilterModel>
    {
        public AutoCheckWireropeDetailPositionMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override CheckWireropeDetailPositionModel Entity2Model(CheckWireropeDetailPosition entity)
        {
            CheckWireropeDetailPositionModel model = new CheckWireropeDetailPositionModel();

            model.CheckWireropeDetailPositionID = entity.CheckWireropeDetailPositionID;
            model.GroupInfoID = entity.GroupInfoID;
            model.UsingWireropeID = entity.UsingWireropeID;
            model.CheckWireropeID = entity.CheckWireropeID;
            model.CheckWireropeDetailID = entity.CheckWireropeDetailID;
            model.DsStart = entity.DsStart;
            model.DsEnd = entity.DsEnd;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override CheckWireropeDetailPosition Model2Entity(CheckWireropeDetailPositionModel model)
        {
            CheckWireropeDetailPosition entity = new CheckWireropeDetailPosition();

            entity.CheckWireropeDetailPositionID = model.CheckWireropeDetailPositionID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.UsingWireropeID = model.UsingWireropeID;
            entity.CheckWireropeID = model.CheckWireropeID;
            entity.CheckWireropeDetailID = model.CheckWireropeDetailID;
            entity.DsStart = model.DsStart;
            entity.DsEnd = model.DsEnd;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<CheckWireropeDetailPosition> FilterModel2Where(CheckWireropeDetailPositionFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._CheckWireropeDetailPositionID.HasValue)
            {
                where = where.And(x => x.CheckWireropeDetailPositionID == filterModel._CheckWireropeDetailPositionID.Value);
            }
            if (filterModel._CheckWireropeDetailPositionIDs.IsNotEmpty() && filterModel._CheckWireropeDetailPositionIDs.Count > 0)
            {
                where = where.And(x => filterModel._CheckWireropeDetailPositionIDs.Contains(x.CheckWireropeDetailPositionID));
            }
            if (filterModel._NotCheckWireropeDetailPositionIDs.IsNotEmpty() && filterModel._NotCheckWireropeDetailPositionIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotCheckWireropeDetailPositionIDs.Contains(x.CheckWireropeDetailPositionID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //在用绳
            if (filterModel._UsingWireropeID.HasValue)
            {
                where = where.And(x => x.UsingWireropeID == filterModel._UsingWireropeID.Value);
            }
            if (filterModel._UsingWireropeIDs.IsNotEmpty() && filterModel._UsingWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._UsingWireropeIDs.Contains(x.UsingWireropeID));
            }
            if (filterModel._NotUsingWireropeIDs.IsNotEmpty() && filterModel._NotUsingWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotUsingWireropeIDs.Contains(x.UsingWireropeID));
            }

            //检测基本信息
            if (filterModel._CheckWireropeID.HasValue)
            {
                where = where.And(x => x.CheckWireropeID == filterModel._CheckWireropeID.Value);
            }
            if (filterModel._CheckWireropeIDs.IsNotEmpty() && filterModel._CheckWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._CheckWireropeIDs.Contains(x.CheckWireropeID));
            }
            if (filterModel._NotCheckWireropeIDs.IsNotEmpty() && filterModel._NotCheckWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotCheckWireropeIDs.Contains(x.CheckWireropeID));
            }

            //检测基本信息详情
            if (filterModel._CheckWireropeDetailID.HasValue)
            {
                where = where.And(x => x.CheckWireropeDetailID == filterModel._CheckWireropeDetailID.Value);
            }
            if (filterModel._CheckWireropeDetailIDs.IsNotEmpty() && filterModel._CheckWireropeDetailIDs.Count > 0)
            {
                where = where.And(x => filterModel._CheckWireropeDetailIDs.Contains(x.CheckWireropeDetailID));
            }
            if (filterModel._NotCheckWireropeDetailIDs.IsNotEmpty() && filterModel._NotCheckWireropeDetailIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotCheckWireropeDetailIDs.Contains(x.CheckWireropeDetailID));
            }

            return where;
        }
        #endregion
    }
}

